linear_algebra Module

This module contains pure functions for basic linear algebra operations.


Uses


Interfaces

public interface eigen

  • private pure function eigen_1(a, right) result(rst)

    Solves the eigenvalue problem where matrix is is square, but not necessarily symmetric. Optionally, the left eigenvalue problem can be solved such that .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The matrix .

    logical, intent(in), optional :: right

    An optional parameter specifying if the right eigenvalue solution should be computed (true), or the left eigenvalue solution should be computed (false). The default is true such that the right eigenvalue problem is solved.

    Return Value type(eigen_solution)

    The solution.

  • private pure function eigen_2(a, b, right) result(rst)

    Solves the eigenvalue problem where and are both N-by-N matrices. Optionally, the left eigenvalue problem can be solved such that .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The matrix .

    real(kind=real64), intent(in), dimension(:,:) :: b

    The matrix .

    logical, intent(in), optional :: right

    An optional parameter specifying if the right eigenvalue solution should be computed (true), or the left eigenvalue solution should be computed (false). The default is true such that the right eigenvalue problem is solved.

    Return Value type(eigen_solution)

    The solution.

public interface solve_least_squares

  • private pure function solve_least_squares_mtx(a, b) result(rst)

    Solves the least squares problem by minimizing using a complete orthogonal factorization of .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The M-by-N matrix .

    real(kind=real64), intent(in), dimension(:,:) :: b

    The M-by-NRHS matrix .

    Return Value real(kind=real64), allocatable, dimension(:,:)

    The resulting N-by-NRHS matrix .

  • private pure function solve_least_squares_vec(a, b) result(rst)

    Solves the least squares problem by minimizing using a complete orthogonal factorization of .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The M-by-N matrix .

    real(kind=real64), intent(in), dimension(:) :: b

    The M-element array .

    Return Value real(kind=real64), allocatable, dimension(:)

    The resulting N-element array .

public interface solve_linear_system

  • private pure function solve_linear_system_mtx(a, b) result(rst)

    Solves the M-by-N linear system for .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The M-by-N matrix .

    real(kind=real64), intent(in), dimension(:,:) :: b

    The M-by-NRHS matrix .

    Return Value real(kind=real64), allocatable, dimension(:,:)

    The resulting N-by-NRHS matrix .

  • private pure function solve_linear_system_vec(a, b) result(rst)

    Solves the M-by-N linear system for .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The M-by-N matrix .

    real(kind=real64), intent(in), dimension(:) :: b

    The M-element array .

    Return Value real(kind=real64), allocatable, dimension(:)

    The resulting N-element array .

public interface solve_triangular_system

  • private pure function solve_triangular_system_mtx(a, b, upper) result(rst)

    Solves a triangular system of the form where is a triangular matrix, either upper or lower, for equation .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The N-by-N triangular matrix.

    real(kind=real64), intent(in), dimension(:,:) :: b

    The N-by-NRHS matrix.

    logical, intent(in), optional :: upper

    An optional argument specifying if the matrix is upper triangular (true), or lower triangular (false). The default assumption is that is an upper triangular matrix.

    Return Value real(kind=real64), allocatable, dimension(:,:)

    The N-by-NRHS solution matrix, .

  • private pure function solve_triangular_system_vec(a, b, upper) result(rst)

    Solves a triangular system of the form where is a triangular matrix, either upper or lower, for equation .

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The N-by-N triangular matrix.

    real(kind=real64), intent(in), dimension(:) :: b

    The N-element array.

    logical, intent(in), optional :: upper

    An optional argument specifying if the matrix is upper triangular (true), or lower triangular (false). The default assumption is that is an upper triangular matrix.

    Return Value real(kind=real64), allocatable, dimension(:)

    The N-element solution array, .


Derived Types

type, public ::  eigen_solution

A container for both eigenvectors and eigenvalues.

Components

Type Visibility Attributes Name Initial
complex(kind=real64), public, allocatable, dimension(:) :: values

An array of eigenvalues.

complex(kind=real64), public, allocatable, dimension(:,:) :: vectors

A collection of eigenvectors, stored columnwise.

type, public ::  lu_factors

A container for the results of a LU factorization.

Components

Type Visibility Attributes Name Initial
real(kind=real64), public, allocatable, dimension(:,:) :: L

The lower-triangular factorization.

real(kind=real64), public, allocatable, dimension(:,:) :: P

The pivot tracking matrix.

real(kind=real64), public, allocatable, dimension(:,:) :: U

The upper-triangular factorization.

type, public ::  qr_factors

A container for the results of a QR factorization of an M-by-N matrix.

Components

Type Visibility Attributes Name Initial
real(kind=real64), public, allocatable, dimension(:,:) :: P

The N-by-N pivot tracking matrix.

real(kind=real64), public, allocatable, dimension(:,:) :: Q

The M-by-M orthogonal matrix, .

real(kind=real64), public, allocatable, dimension(:,:) :: R

The M-by-N upper trapezoidal matrix, .

type, public ::  svd_factors

A container for the results of a singular value decomposition of an M-by-N matrix.

Components

Type Visibility Attributes Name Initial
real(kind=real64), public, allocatable, dimension(:,:) :: S

The M-by-N diagonal matrix containing the singular values on the diagonal.

real(kind=real64), public, allocatable, dimension(:,:) :: U

The M-by-M orthogonal matrix .

real(kind=real64), public, allocatable, dimension(:,:) :: Vt

The transpose of the N-by-N right singular vector matrix .


Functions

public pure function cholesky_factor(a, upper) result(rst)

Computes the Cholesky factorization of a positive-definite matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The matrix to factor.

logical, intent(in), optional :: upper

An optional parameter to specifiy if the upper factorization should be computed (true); else, false for the lower factorization . The default is to compute the upper factorization.

Return Value real(kind=real64), allocatable, dimension(:,:)

The factored matrix, either or .

public pure function identity(n) result(rst)

Constructs an N-by-N identity matrix.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: n

The size of the matrix.

Return Value real(kind=real64), allocatable, dimension(:,:)

The resulting matrix.

public pure function inverse(a) result(rst)

Computes the inverse of a square matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The N-by-N matrix to invert.

Return Value real(kind=real64), allocatable, dimension(:,:)

The N-by-N inverted matrix.

public pure function lu_factor(a) result(rst)

Computes the LU factorization of a square matrix such that .

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The N-by-N matrix to factor.

Return Value type(lu_factors)

The factored form of the matrix.

public pure function pinverse(a) result(rst)

Computes the Moore-Penrose pseudoinverse of an M-by-N matrix.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The M-by-N matrix to invert.

Return Value real(kind=real64), allocatable, dimension(:,:)

The N-by-M inverted matrix.

public pure function qr_factor(a, pivot) result(rst)

Computes the QR factorization of an M-by-N matrix such that either (no pivoting), or (with pivoting).

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The M-by-N matrix to factor.

logical, intent(in), optional :: pivot

An optional parameter used to specifiy if pivoting should be used (true); else, false if no pivoting is used. The default is false such that no pivoting is performed.

Return Value type(qr_factors)

The factored form of the matrix.

public pure function svd(a) result(rst)

Computes the singular value decomposition of an M-by-N matrix such that .

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in), dimension(:,:) :: a

The M-by-N matrix to factor.

Return Value type(svd_factors)

The factored form of the matrix.


Subroutines

public pure subroutine swap_arrays(x, y)

Swaps the contents of two arrays.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(inout), dimension(:) :: x

The first array.

real(kind=real64), intent(inout), dimension(:) :: y

The second array.